import { loadModules } from 'esri-loader';
const METER = 9001;
const KILOMETER = 9036;
const SQUARE_METER = 109404;
const SQUARE_KILOMETER = 0;

let geoEngine;

function MapTools() {
    if(!geoEngine){
        loadModules(['esri/geometry/geometryEngine'])
        .then(([geometryEngine]) => {
            geoEngine = geometryEngine;
        })
    }
}
MapTools.prototype.measureLength = function(geometry,succFun){
    let result = geoEngine.planarLength(geometry, METER);
    if(succFun && typeof succFun=='function'){
        succFun(result);
    }
    return result;
}
MapTools.prototype.measureArea = function(geometry,succFun){
    let result = geoEngine.planarArea(geometry, SQUARE_METER);
    if(succFun && typeof succFun=='function'){
        succFun(result);
    }
    return result;
}
MapTools.prototype.bufferGeo = function(geometry, distance,succFun){
    // debugger
    let result = geoEngine.buffer(geometry, distance, METER);
    if(succFun && typeof succFun=='function'){
        succFun(result);
    }
    return result;
}
MapTools.prototype.isIntersect = function(geometry1, geometry2){
    return geoEngine.intersects(geometry1, geometry2);
}
MapTools.prototype.intersect = function(geometries, geometry){
    return geoEngine.intersect(geometries, geometry);
}

export default MapTools